<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * 中文
 */

/**
 * Description of publicfunc
 *
 * @author root
 */
class publicfunc {
    public $dba;
    
    public function __construct() {
        $this->dba = new db();
    }
    
    public function get_channel_son($id){
        $data = $this->dba->fetch_arrone("select id,parent_id from channel where id=\"$id\";");
        if($data['parent_id']=='0'){
            $data = $this->dba->fetch_all("select id,name,type,parent_id,sort from channel where parent_id=\"$id\" order by sort");
            return $data;
        }else{
            $data = $this->dba->fetch_arrone("select id,parent_id from channel where id=\"$id\";");
            $id = $data['parent_id'];
            $data = $this->dba->fetch_all("select id,name,type,parent_id,sort from channel where parent_id=\"$id\" order by sort");
            return $data;
        }
        
    }
    
    public function get_channel_parent(){
        $data = $this->dba->fetch_all("select id,name,type,parent_id,sort from channel where parent_id='0' order by sort");
        return $data;
    }
    
    public function get_current_id($id){
        $data = $this->dba->fetch_arrone("select id,name,type,parent_id,sort from channel where id=\"$id\";");
        if($data['parent_id'] !=0){
            $str = "'".$data['id']."'".",'".$data['parent_id']."'";
        }else{
            $str = "'".$data['id']."'";
        }
        $data = $this->dba->fetch_arrone("select id,name,type,parent_id,sort from channel where `parent_id`=\"$id\" order by `sort` limit 1");
        $str .= ','."'".$data['id']."'";
        return $str;
    }
    
    public function getdocument(){
        $data = $this->dba->fetch_all("select id,title,date,channel,channel_name from article order by `date` desc limit 10");
        return $data;
    }
    
}

?>
